package com.wjk.cms.controller;

import com.wjk.cms.common.Result;
import com.wjk.cms.pojo.User;
import com.wjk.cms.util.UploadUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class SysUploadController extends AuthenticatedController {

    @Autowired
    private UploadUtil uploadUtil;

    @PostMapping("/sys/upload")
    public Result product(
            @RequestParam("category") String category, // 类别，小写英文字母+数字，所有类别不可重复
            @RequestParam("file") MultipartFile file // 要上传的文件
    ) {
        User currentUser = getCurrentUser();
        return Result.ok().add("url", uploadUtil.upload(file, currentUser.getName(), category));
    }

    @PostMapping("/sys/upload_bk")
    public Result upload_bk(
            @RequestParam("category") String category, // 类别，小写英文字母+数字，所有类别不可重复
            @RequestParam("file") MultipartFile file // 要上传的文件
    ) {
        User currentUser = getCurrentUser();
        return Result.ok().add("url", uploadUtil.uploadBk(file, currentUser.getName(), category));
    }

}
